package com.htl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.htl.entity.OrderMaster;
import com.htl.mapper.OrderMasterMapper;
import com.htl.service.OrderMasterService;
import com.htl.util.ResultVOUtil;
import com.htl.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 订单详情表 前端控制器
 * </p>
 *
 * @author 韩天乐
 * @since 2021-11-14
 */

@RestController
@RequestMapping("/seller/order")
public class SellerOrderController {

    @Autowired
    private OrderMasterService orderMasterService;

    @Autowired
    private OrderMasterMapper orderMasterMapper;

    @GetMapping("/list/{page}/{size}")
    public ResultVO list(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size
    ){
        Page<OrderMaster> page1 = new Page<>(page,size);
        Page<OrderMaster> page2 = this.orderMasterService.page(page1);
        Map<String,Object> map = new HashMap<>();
        map.put("content", page2.getRecords());
        map.put("size", page2.getSize());
        map.put("total", page2.getTotal());
        return ResultVOUtil.success(map);
    }


    @PutMapping("/cancel/{orderId}")
    public ResultVO cancel(@PathVariable("orderId") String orderId){
        Boolean aBoolean = this.orderMasterMapper.updateStatusByOrderId(orderId, 2);
        if (aBoolean) return ResultVOUtil.success(null);
        return ResultVOUtil.fail(null);
    }

    @PutMapping("/finish/{orderId}")
    public ResultVO finish(@PathVariable("orderId") String orderId){
        Boolean aBoolean = this.orderMasterMapper.updateStatusByOrderId(orderId, 1);
        if (aBoolean) return ResultVOUtil.success(null);
        return ResultVOUtil.fail(null);
    }


    @GetMapping("/barSale")
    public ResultVO barSale(){
        return ResultVOUtil.success(this.orderMasterService.createBarData());
    }


    @GetMapping("/basicLineSale")
    public ResultVO basicLineSale(){
        return ResultVOUtil.success(this.orderMasterService.createBaseLineData());
    }


    @GetMapping("/stackedLineSale")
    public ResultVO stackedLineSale(){
        return ResultVOUtil.success(this.orderMasterService.createStackedData());
    }

}

